package org.insia.smartposse.mapping.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import org.insia.smartposse.manager.UserManager;
import org.insia.smartposse.mapping.FreelanceSkills;
import org.insia.smartposse.mapping.Skills;
import org.insia.smartposse.mapping.Users;
import org.insia.smartposse.mapping.base.BaseFreelanceSkillsDAO;


public class FreelanceSkillsDAO extends BaseFreelanceSkillsDAO implements org.insia.smartposse.mapping.dao.iface.FreelanceSkillsDAO {

	public FreelanceSkillsDAO () {}
	
	public FreelanceSkillsDAO (Session session) {
		super(session);
	}

	public FreelanceSkills getFRByUserSkill(Users user, int skill, Session session) {
		return (FreelanceSkills) session.createCriteria(getReferenceClass())
		.add(Expression.eq("Freelance", user))
		.add(Expression.eq("Skill", new Skills(skill)))
		.uniqueResult();
	}
	
	@SuppressWarnings("unchecked")
	public List<FreelanceSkills> findByUser(UserManager user, Session session) {
		return session.createCriteria(getReferenceClass())
		.add(Expression.eq("Freelance", user.getUser()))
		.list();
	}
}